Post marked as Apple Recommended
Click to stop watching this thread.
You have stopped watching this post. Click to start watching again.
contentPostList.repliesapple-recommended.tooltip
Replied In
convert tuple to swift array
I've adjusted the original answer to make it more generic and also to support the other element types on top of UInt8.
extension Array {
static func from(tuple: Any, start: UnsafePointer<Element>) -> [Element] {
[Element](
UnsafeBufferPointer(
start: start,
count: MemoryLayout.size(ofValue: tuple)/MemoryLayout<Element>.size
)
)
}
}
var someTuple: (Double, Double, Double) = (1, 2, 3)
let array: [Double] = .from(tuple: someTuple, start: &someTuple.0)